
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class AlbumForm extends List implements CommandListener, Runnable {

    private Command cmdAddNew;
    private HomeScreen homeScreen;
    private int total;

    public AlbumForm(HomeScreen homeScreen) {
        super("UpAnh", IMPLICIT);
        this.homeScreen = homeScreen;
        cmdAddNew = new Command("New", Command.OK, 2);
        setCommandListener(this);
        addCommand(cmdAddNew);
        Common.Client.ViewListAlbum();
        append("Them moi Album", null);
        total = 1;
        new Thread(this).start();
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdAddNew) {
            homeScreen.DisplayAddNewAlbum();
        }
        if (c == SELECT_COMMAND) {
            if (getSelectedIndex() == total - 1) {
                homeScreen.DisplayAddNewAlbum();
            } else {
                Common.AlbumId = getSelectedIndex();
                homeScreen.DisplayChoseUploadForm();
            }
        }
    }

    public void run() {
        while (true) {
            if (Common.Client.albumList.size() > 0) {
                this.deleteAll();
                for (int i = 0; i < Common.Client.albumList.size() - 1; i++) {
                    append(Common.Client.albumList.elementAt(i).toString(), null);
                }
                total = Common.Client.albumList.size();
                append("Them moi Album", null);
                Common.Client.albumList.removeAllElements();
                return;
            }
            System.gc();
        }
    }
}
